package com.cskaoyan.service;

import com.cskaoyan.bean.Category;
import com.cskaoyan.bean.CategoryExample;
import com.cskaoyan.bean.vo.WxCatalogIndexVO;
import com.cskaoyan.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author heyyon
 */
@Service
public class WxCatalogServiceImpl implements WxCatalogService{
    @Autowired
    CategoryMapper categoryMapper;
    @Override
    public WxCatalogIndexVO index() {
        CategoryExample categoryExample = new CategoryExample();
        CategoryExample.Criteria criteria=categoryExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        List<Category> categories = categoryMapper.selectByExample(categoryExample);
        WxCatalogIndexVO wxCatalogIndexVO = new WxCatalogIndexVO();
        Category category = categoryMapper.selectFirstCategory();
        wxCatalogIndexVO.setCurrentCategory(category);
        wxCatalogIndexVO.setCategoryList(categories);
        categories = categoryMapper.selectSubCategory();
        wxCatalogIndexVO.setCurrentSubCategory(categories);
        return wxCatalogIndexVO;
    }

    @Override
    public WxCatalogIndexVO current(Integer id) {
        CategoryExample categoryExample = new CategoryExample();
        CategoryExample.Criteria criteria=categoryExample.createCriteria();
        if (id != null) {
            criteria.andIdEqualTo(id);
        }
        List<Category> categories = categoryMapper.selectByExample(categoryExample);
        WxCatalogIndexVO wxCatalogIndexVO = new WxCatalogIndexVO();
        wxCatalogIndexVO.setCurrentCategory(categories.get(0));
        categories=categoryMapper.selectSubCategoryById(id);
        wxCatalogIndexVO.setCurrentSubCategory(categories);
        return wxCatalogIndexVO;
    }
}
